package com.threadlocal;

import java.util.Date;

class ToolsDate {
	public static ThreadLocal<Date> tl = new ThreadLocal<Date>();
}
class ThreadC extends Thread{
	@Override
	public void run() {
		try {
			for(int i=0;i <20; i++){
				if(ToolsDate.tl.get() == null){
					ToolsDate.tl.set(new Date());
				}
				System.out.println("A "+ ToolsDate.tl.get().getTime());
				Thread.sleep(100);
			}
		} catch (Exception e) {
		}
	}
}
class ThreadD extends Thread{
	@Override
	public void run() {
		try {
			for(int i=0;i <20; i++){
				if(ToolsDate.tl.get() == null){
					ToolsDate.tl.set(new Date());
				}
				System.out.println("B "+ ToolsDate.tl.get().getTime());
				Thread.sleep(100);
			}
		} catch (Exception e) {
		}
	}
}
public class Run3 {

	public static void main(String[] args) {
		try {
			ThreadC c = new ThreadC();
			c.start();
			Thread.sleep(1000);
			ThreadD d = new ThreadD();
			d.start();
		} catch (Exception e) {

		}
	}

}
